<?php
class FuliModel extends Model {

	public function get_primary_key() {
		return $this->primary_key = 'id';
	}

    public function set($id, $data) {
        if ($id) {
            $this->db->update('member_fuli', $data,array('id'=>$id));
            return $id;
        }
        $return = $this->db->insert('member_fuli', $data);
        if ($return) return $return;
        return false;
    }

    public function del($member_id,$id)
    {
        $this->db->delete('member_fuli',array('id'=>$id,'member_id'=>$member_id));
        return $id;
    }

    public function del2($id)
    {
        $this->db->delete('member_fuli',array('id'=>$id));
        return $id;
    }

    public function get_wuliu_show($id){
        $sql = "select m.kuaidien,m.kuaidihao,mi.address,mi.province,mi.city,mi.area from ".$this->prefix."member_fuli as m
        left join ".$this->prefix."member_info as mi on m.address = mi.id
        where m.id = $id";
        $res = $this->db->query($sql)->row_array();
        return $res;
    }
	//后台
	public function get_admin_list($where,$order,$limit,$ifcount=false){
		if($ifcount){
			$sql = "select count(m.id) as total from ".$this->prefix . "member_fuli as m
            left join ".$this->prefix."member as me on m.member_id = me.id
            left join ".$this->prefix."content_1 as c on m.number = c.id
					where $where";
			$res = $this->db->query($sql)->row_array();
			return $res['total'];
		}
		$sql = "select m.*,me.name,me.username,c.title,c.description from ".$this->prefix . "member_fuli as m
		left join ".$this->prefix."member as me on m.member_id = me.id
		left join ".$this->prefix."content_1 as c on m.number = c.id
		        where $where order by $order limit $limit";
		$res = $this->db->query($sql)->result_array();
		return $res;
	}

//前台
    public function get_fuli_list($where,$order,$limit,$ifcount=false){
        if($ifcount){
            $sql = "select count(m.id) as total from ".$this->prefix . "member_fuli as m
            left join ".$this->prefix."member as me on m.member_id = me.id
            left join ".$this->prefix."content_1 as c on m.number = c.id
                    where $where";
            $res = $this->db->query($sql)->row_array();
            return $res['total'];
        }
        $sql = "select m.*,me.name,me.username,c.title,c.description,cf.zengpintupian from ".$this->prefix . "member_fuli as m
        left join ".$this->prefix."member as me on m.member_id = me.id
        left join ".$this->prefix."content_1 as c on m.number = c.id
        left join ".$this->prefix."content_1_fuli as cf on cf.id = c.id where $where order by $order limit $limit";
        $res = $this->db->query($sql)->result_array();
        return $res;
    }
    public function get_one($where){
        $sql = "select * from ".$this->prefix."member_fuli where $where";
        $res = $this->db->query($sql)->row_array();
        return $res;
    }

    public function get_address($where){
        $sql = "select m.*,mi.name,mi.username,mi.pca,mi.address from ".$this->prefix."member_fuli as m 
        left join ".$this->prefix."member_info as mi on m.address = mi.id
        where $where";
        $res = $this->db->query($sql)->row_array();
        return $res;
    }
	
	
	
	
	
	


}